Wiki

Clone wiki

khk-independent / Dashboard view

Dashboard view

  • Write the HTML to display the summary table in dash/index.php
  • Table rows are, again, printed by iterating over a collection

Two roads...

Two roads diverged in a yellow wood,    
And sorry I could not travel both   
And be one traveler, long I stood   
And looked down one as far as I could   
To where it bent in the undergrowth;

Here you have a choice in how to implement the table rows - how to fetch the data. There are two options...

Doing it in SQL

The idea is that you write a new method, Model_Employee::get_year_summary($year). The method takes a year and returns a data structure (this could be a simple array or a specialized object) that contains the needed data to print out the row: employee name, time spent per month etc.

You get the data by writing a long-ish SQL using the Database module. It'd look something like this (pseudocode warning):

<?
DB::select('puppies.name', [DB::expr('COUNT(number_of_legs)'),'puppie_leg_number'])
->join('owners')->on('owners.id','=','puppies.owner_id')
->from('puppies')
->where('year_of_birth','=', 2012)
->execute();

...or whatever - you get the picture. The advantage of this is that you get a really nice array-like structure back that has exactly the information you selected and needed to print your row... but it's arguably more difficult to implement and not as reusable.

Doing it via object methods

Another way would be to leverage the power of ORM and query the data via object relations, then aggregate [task sum] data with PHP.

  • Find all employees (table rows)
  • For each employee...
    • Find all tasks that employee did during the year
    • Group the tasks by month
    • Use a static PHP method that aggregates the time for each group of task-months
    • Do the same to find the total pay

You'll end up with an array (or an object) with the needed data, which can then be printed out. The methods are reusable-ish, but it's also slower since the computer has to allocate memory for all that iteration.


Pick a method (the SQL one is probably easier to understand) and implement it. Do this in your model. The view asks this data from Model_Employee and passes it to the view. The view iterates the rows and prints them out.

  • About the months - each month cell should link to that employees view, for that particular month:
http://localhost/jolly/employees/view/3?month=4&year=2013

Adding a new employee

Remember how we did the new-task MVC? Also remember me telling you that a LOT of stuff is just basic CRUD?

Adding a new employee is really-really similar to adding a new task. Use what you learned from implementing the task addition to do this. Heck, you only have one field.

  • Remember, employee = user in our context.

Finishing up

  • Add the database dump (exported sql of your mysql database) to Git
  • Do your last commit - and push it to GitHub
  • Just for fun, tag it with khk-payroll-final
  • Deploy it to the staging server for the world (instructors) to see

Fine

You're done. Thank you for participating; I hope you learned a LOT, although the pace was really fast.

I'd appreciate feedback about this course/tutorial/project: Was it really difficult? Did you know enough about programming to keep up? Were the instructions easy to follow? Would you have preferred more help?

The best, /Ando Roots, ando.roots@diara.ee

Updated